<?php
//
//  VictoryCMS - Content managment system and framework.
//  Copyright (C) 2009  Lewis Gunsch
//
//  This file is part of VictoryCMS.
//  
//  VictoryCMS is free software: you can redistribute it and/or modify
//  it under the terms of the GNU General Public License as published by
//  the Free Software Foundation, either version 3 of the License, or
//  (at your option) any later version.
//
//  VictoryCMS is distributed in the hope that it will be useful,
//  but WITHOUT ANY WARRANTY; without even the implied warranty of
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//  GNU General Public License for more details.
//  
//  You should have received a copy of the GNU General Public License
//  along with VictoryCMS.  If not, see <http://www.gnu.org/licenses/>.

/**
 * VictoryCMS - PageBuilderFactory
 * 
 * @license http://www.gnu.org/licenses/gpl.html
 * @author Lewis Gunsch
 * @filesource
 * @package PageBuilders
 */

/**
 * @package PageBuilders
 *
 * @todo Add in a method to list available PageBuilders
 * @todo Finish documentation
 */
class PageBuilderFactory {

	/**
	 *
	 * @param $name Name of the PageBuilder to create.
	 * @return PageBuilder instance of PageBuilder.
	 *
	 * @todo create custom exception here
	 */
	public static function createPageBuilder($name) {

		$success = loadFromFolder($name, FolderMap::getPageBuilderFolder());
		// if debugging is enabled then try to load from test folder
		// which should be under the pagebuilders folder
		if ($success == false && VarMap::get(VarMapKeys::debug_enabled) == true) {
			$success = loadFromFolder($name, FolderMap::getTestingPageBuilderFolder());
		}
		if ($success == true) {
			$classInst = new $name;
		} else {
			throw new NotFoundException($name);
		}
		if (!$classInst instanceof PageBuilder) {
			throw new DataTypeException('PageBuilder', $name);
		}
		return $classInst;
	}
}
?>
